<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>衣物回收管理</title>
</head>
<link rel="stylesheet" href="../res/layui/css/layui.css" media="all">
<script src="../res/js/jquery-3.1.1.min.js" type="text/javascript"
        charset="utf-8"></script>
<script src="../res/js/login_common.js"></script>
<script src="../res/layui/layui.js" charset="utf-8"></script>
<body>
</head>
<body style="padding: 5px;">
<div class="demoTable">
    <button type="button" class="layui-btn layui-btn-normal" id="add">增加衣物回收</button>
    <table class="layui-hide" id="test" lay-filter="test"></table>
    <script>
        $(function(){
            $("#add").click(function(){
                //iframe层
                layer.open({
                    type: 2,
                    title: '衣物回收增加页面',
                    shadeClose: true,
                    shade: 0.8,
                    area: ['50%', '50%'],
                    content: 'yiwuhuishouadd.html', //iframe的url
                    end:function(){
                        table2.reload();
                    }
                });
            })
        })
        var table2=null;
        layui.use('table', function(){
            var table = layui.table;
            table2= table.render({
                elem: '#test'
                ,url:'../UserController/selectHuishouAll'
                ,page: true //开启分页
                ,title: '用户数据表'
                ,cols: [[
                    {field:'coName', title:'衣物名称', width:180}
                    ,{field:'coNum', title:'衣物数量', width:120}
                    ,{field:'voPerson', title:'回收人', width:120}
                ]]
            });


            //监听行工具事件
            table.on('tool(test)', function(obj){
                var data = obj.data;
                //console.log(obj)
                if(obj.event === 'del'){
                    layer.confirm('真的删除行么', function(index){
                        obj.del();
                        layer.close(index);
                        var url="../UserController/delete";
                        var dataone={"clId":data.clId};
                        $.post(url,dataone,function(obj){
                            if(obj.num==1){
                                layer.msg(obj.msg,{
                                    icon:1,
                                    time:1000 //1秒关闭(如果不配置默认三秒)
                                },function(){
                                    //刷新父页面
                                    parent.location.reload();
                                });
                            }else{
                                layer.msg(obj.msg);
                            }
                        },"json")
                    });
                } else if(obj.event === 'edit'){
                    var data1 = obj.data;//获取当前行
                    //iframe层
                    layer.open({
                        type: 2,
                        title: '菜单修改页面',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['60%', '56%'],
                        content: 'jsp/shangjiajsp/cdlbaddOrupdate.jsp?id='+data1.menuID, //iframe的url
                        end:function(){
                            table2.reload();
                        }
                    });
                }
            });


            //头工具栏事件
            table.on('toolbar(test)', function(obj){
                var checkStatus = table.checkStatus(obj.config.id);
                switch(obj.event){
                    case 'getCheckData':
                        layer.confirm('真的删除行么', function(index){
                            var data = checkStatus.data;
                            //layer.alert(JSON.stringify(data));
                            var ids="";//需要删除的id
                            $.each(data,function(index,idem){
                                ids+=idem.menuID+",";
                            })
                            if(ids==""){
                                layer.msg("请您选中需要删除的内容,不能为空!");
                            }
                            var url="MenuServlet?action=deleteAllone";
                            var datas={ids:ids};
                            $.post(url,datas,function(obj){
                                layer.msg(obj.msg);
                                table2.reload();//刷新表格
                            },"json");
                        });
                        break;
                };
            });
        });
    </script>
    <script type="text/html" id="barDemo">
        <a id="das" class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>
    <script type="text/html" id="titleTpl">
        <img src='{{d.menuImage}}' alt='照片' onclick='showImg(this)' />
    </script>
    <script type="text/html" id="titleTpll">
        <img src='{{d.shoplicenceImg}}' alt='照片' onclick='showImg(this)' />
    </script>

</body>
</body>
</html>